using System;
using FytSoa.Common.Utils;
using System.ComponentModel.DataAnnotations;
using FytSoa.Application.Crm;
using FytSoa.Application.Hr;
using FytSoa.Common.Enum;
using FytSoa.Domain;
using FytSoa.Domain.Crm;
using FytSoa.Domain.Erp;
using SqlSugar;

namespace FytSoa.Application.Erp;

/// <summary>
/// 生产订单
/// </summary>
public class ErpProduceOrderDto : AppEntity
{
    /// <summary>
    /// 生产编号
    /// </summary>
    [Required]
    [StringLength(30)]
    public string Number { get; set; }

    /// <summary>
    /// 订单名称
    /// </summary>
    [StringLength(100)]
    public string Name { get; set; }

    /// <summary>
    /// 项目订单编号
    /// </summary>
    [Required]
    public long ProjectId { get; set; }
    
    /// <summary>
    /// 项目订单
    /// </summary>
    public CrmProjectSimpleDto Project { get; set; }

    /// <summary>
    /// 生产负责人
    /// </summary>
    [Required]
    public long ChargePersonId { get; set; }
    
    /// <summary>
    /// 负责人
    /// </summary>
    public HrEmployeeSimpleDto Employee { get; set; }

    /// <summary>
    /// 数量
    /// </summary>
    [Required]
    public int Count { get; set; } = 0;
    
    /// <summary>
    /// 是否申请物料
    /// </summary>
    public bool IsApply { get; set; } = false;

    /// <summary>
    /// 接单日期
    /// </summary>
    public DateTime? AcceptTime { get; set; }

    /// <summary>
    /// 设计完成时间
    /// </summary>
    public DateTime? DesignTime { get; set; }
    
    /// <summary>
    /// 是否需要设计
    /// </summary>
    public bool IsDesign { get; set; } = false;
    
    /// <summary>
    /// 设计过程
    /// </summary>
    [SugarColumn(IsJson = true)]
    public ErpProduceOrder.DesignProcessModel DesignProcess { get; set; } = new();
    
    /// <summary>
    /// 设计负责人
    /// </summary>
    [Required]
    public long DesignPersonId { get; set; }
    
    /// <summary>
    /// 设计负责人
    /// </summary>
    public HrEmployeeSimpleDto DesignEmployee { get; set; }

    /// <summary>
    /// 设计完成时间
    /// </summary>
    public DateTime? ProduceTime { get; set; }
    
    /// <summary>
    /// 附件
    /// </summary>
    public List<FileBase> Files { get; set; } = new();
    
    /// <summary>
    /// 阶段 1/下单2/工程3/设计4/制作5/品控6/完成
    /// </summary>
    public ErpProducePhaseEnum Phase { get; set; } = ErpProducePhaseEnum.Placed;

    /// <summary>
    /// 审核 0=未审核
    /// </summary>
    public ErpAuditEnum Status { get; set; } = ErpAuditEnum.NotReviewed;
    
    /// <summary>
    /// 审批流程
    /// </summary>
    [Required]
    public long FlowId { get; set; } = 0;

    /// <summary>
    /// 审批流程详情
    /// </summary>
    [Required]
    public ErpFlowDto.ErpFlowSimpleDto Flow { get; set; } = new();
    
    /// <summary>
    /// 品控状态0待接收/1已接收/2已开工/3已完成
    /// </summary>
    public int ControlStatus { get; set; } = 0;
    
    /// <summary>
    /// 品控工时
    /// </summary>
    public double ControlHour { get; set; } = 0;

    /// <summary>
    /// 品控进度
    /// </summary>
    public List<ErpProduceOrder.DesignProcessModel.ProcessModel> ControlProcess { get; set; } = new();

    /// <summary>
    /// 品控驳回原因及回复
    /// </summary>
    public ErpProduceOrder.ControlCauseModel ControlCause { get; set; } = new();
    
    /// <summary>
    /// 备注说明
    /// </summary>
    public string Remark { get; set; }

    /// <summary>
    /// 自定义属性
    /// </summary>
    public List<KeyValueBase> CustomAttr { get; set; } = new();
    
    /// <summary>
    /// 关闭原因
    /// </summary>
    public string CloseRemark { get; set; }

    /// <summary>
    /// 创建人
    /// </summary>
    public string CreateUser { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    [Required]
    public DateTime CreateTime { get; set; } = DateTime.Now;

    /// <summary>
    /// 更新人
    /// </summary>
    public string UpdateUser { get; set; }

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime? UpdateTime { get; set; }


}

public class ErpProduceOrderSimpleDto : AppEntity
{
    public string Name { get; set; }
    
    public string Number { get; set; }
}